/*
 * pps.h
 *
 *  Created on: 2014-9-26
 *      Author: Administrator
 */

#ifndef PPS_H_
#define PPS_H_
#include <ctype.h>
#define SKIPS(p) do { while(isspace(*(p))) ++(p); } while (0) // Skip space
#define SKIPT(p) do { while(*(p) && *(p) != '\n') ++(p); } while (0); // Skip to EOL

#define PPS_PARAM	25
//PPS encoder data MACRO Start
#define PPS_ENCODER_START(p_encoder,name)		pps_encoder_initialize(p_encoder, false);	\
												pps_encoder_start_object(p_encoder, name)

#define PPS_ENCODER_StartJson(p_encoder,name)	pps_encoder_start_object(p_encoder, name);
#define PPS_ENCODER_EndJson(p_encoder)			pps_encoder_end_object(p_encoder);

#define PPS_ENCODER_FLUSH(p_encoder,fd)			if ( pps_encoder_buffer(p_encoder) != NULL ) {	\
													write(fd, pps_encoder_buffer(p_encoder), pps_encoder_length(p_encoder));	\
												}	\
												pps_encoder_cleanup(p_encoder)
//PPS encoder data MACRO End
///////////////////////////////////////////////////////////////////////////////////
//PPS decoder data MACRO Start
#define PPS_DECODER_START(p_decoder,buffer)		pps_decoder_initialize(p_decoder, NULL);	\
												pps_decoder_parse_pps_str(p_decoder, buffer);	\
												pps_decoder_push(p_decoder, NULL)

#define PPS_DECODER_StartJson(p_decoder,name)	pps_decoder_push(p_decoder, name)
#define PPS_DECODER_EndJson(p_decoder)			pps_decoder_pop(p_decoder)

#define PPS_DECODER_FLUSH(p_decoder)			pps_decoder_pop(p_decoder);				\
												if ( pps_decoder_status(p_decoder, false) != PPS_DECODER_OK ) {	\
    												fprintf(stderr,"Pps decoder failed in %s!\n",__FUNCTION__);	\
												}	\
												pps_decoder_cleanup(p_decoder)

//PPS decoder data MACRO End


// use for the pps obj with more than one attr
#define write_pps_buf(buf, strFmt, fd, attr ,val)\
					flushall();\
					sprintf(buf, strFmt,attr, val);\
					write(fd, buf, strlen(buf));\
					flushall();

int ppsParse(char **const optionp, char * const *tokens, char **const valuep, char **const encoding);
int GetPpsValue(const char* ppsDir,char* ppsAttr);
int SetPpsValue(const char* ppsDir,char* ppsAttr,int value);
int SetPpsValues(const char* ppsDir,char* ppsBuf);
#endif /* PPS_H_ */
